package com.neuedu.boot.mybatis.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.neuedu.boot.mybatis.mapper.DeptMapper;
import com.neuedu.boot.mybatis.po.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 金山
 * 项目：boot-learn
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/219:47
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptMapper deptMapper;


    /**
     * http://localhost:8080/dept/getById
     * @return
     */
    @RequestMapping("/getById")
    Dept getById()  {
        long id  = 1;
        return  deptMapper.selectByPrimaryKey(id);
    }

    @RequestMapping("/list")
    List<Dept> list()  {



        List<Dept> depts = deptMapper.selectList();

        return  depts;
    }


    /**
     * http://localhost:8080/dept/page?pageNum=1&pageSize=5
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/page")
    List<Dept> page(@RequestParam(defaultValue = "1") int pageNum ,@RequestParam(defaultValue = "5") int pageSize)  {

        //开启分页

        //PageHelper.startPage(1页 , 5 条)
        //PageHelper.startPage(2页 , 5 条)
        Page<Dept> page = PageHelper.startPage(pageNum, pageSize);
         deptMapper.selectList();
        System.out.println(page.toString());

        System.out.println("page.getPages() = " + page.getPages());
        System.out.println("page.getTotal() = " + page.getTotal());
        System.out.println("page.getPageSize() = " + page.getPageSize());
        System.out.println("page.getPageNum() = " + page.getPageNum());
        System.out.println("page.getPages() = " + page.getPages());

        List<Dept> deptList = page.getResult();
        return  deptList;
    }
}
